%pylab inline
import matplotlib.pyplot as plt
from ipywidgets import *
def Lorentz(V):
'''
Lorentz transformation
'''
th=V
ch=1/sqrt(1-th**2)
sh=th*ch
Lm=matrix([[ch,-sh],[-sh,ch]])
return(Lm)
def coords(V):
'''
Calculate the unit vectors 'xvec,tvec' along the axises x', t' in system K'
'''
th=V
szog=arctan(V)
xvec=array([cos(szog),sin(szog)])
tvec=array([cos(pi/2-szog),sin(pi/2-szog)])
return(xvec,tvec)
def tengelyek(V):
'''
plotting x', t' axises in K'
'''
figsize(12,8)
#ax=subplot(aspect='equal')
ax=subplot(111,aspect='equal')
vecxv,vectv=coords(V)
fact=5
plot([0,fact*1],[0,0],'-b')
plot([0,0],[0,fact*1],'-b')
plot([0,fact*1],[0,fact*1],'--k')
plot([-fact*vecxv[0],fact*vecxv[0]],[-fact*vecxv[1],fact*vecxv[1]],'-r')
plot([-fact*vectv[0],fact*vectv[0]],[-fact*vectv[1],fact*vectv[1]],'-r');
text(0,fact*1,'$t$',fontsize=20)
text(fact*1,0,'$x$',fontsize=20)
text(fact*vectv[0],fact*vectv[1],'$t^\prime$',fontsize=20)
text(fact*vecxv[0],fact*vecxv[1],'$x^\prime$',fontsize=20)
return(vecxv,vectv)
def indicatrix(chimax):
'''
plotting the indicatrix for x and t, ie units of x and t
'''
chi=linspace(-chimax,chimax,100)
plot(sinh(chi),cosh(chi),'-',color='magenta');
plot(cosh(chi),sinh(chi),'-',color='magenta');
def vetites(vecxv,vectv,Ep,betu,szin):
'''
calculation of the coordinates in skew coordinates, in K', projection
'''
#Ep esemeny K-ban
plot(Ep[0], Ep[1], marker='o', markersize=9, color=szin)
pos=1.05
text(pos*Ep[0], pos*Ep[1],betu,fontsize=20,color=szin)
mm=array([[dot(vecxv,vecxv),dot(vecxv,vectv)],[dot(vectv,vecxv),dot(vectv,vectv)]])
b=array([dot(vecxv,Ep),dot(vectv,Ep)])
av = linalg.solve(mm, b)
tmp=vecxv*av[0]
plot([tmp[0],Ep[0]],[tmp[1],Ep[1]],'--',color=szin)
tmp=vectv*av[1]
plot([tmp[0],Ep[0]],[tmp[1],Ep[1]],'--',color=szin)
def rajz_esemeny(V,Ep,betu,szin):
'''
plotting the coordinates of the event Ep in K' if it is given in K.
'''
vecxv,vectv=tengelyek(V)
vetites(vecxv,vectv,Ep,betu,szin)
grid();
def rajz_2esemeny(V,Ep1,Ep2,betu1,szin1,betu2,szin2):
'''
plotting the coordinates of the event Ep1 and Ep2 in K' if it is given in K.
'''
vecxv,vectv=tengelyek(V)
#Ep1 esemeny K-ban
vetites(vecxv,vectv,Ep1,betu1,szin1)
#Ep2 esemeny K-ban
vetites(vecxv,vectv,Ep2,betu2,szin2)
plot([Ep1[0],Ep2[0]],[Ep1[1],Ep2[1]],'-b',lw=3)
grid();
Lm=Lorentz(0.6)
xk=matrix(array([[1],[6]]))
xkv=Lm*xk
Lm, Lm*xk,xkv,array(xkv)[1][0]
V=-0.4
vecxv,vectv=tengelyek(V)
vecxv
V=0.6
fact=3
Ep =fact*array([0.6,0.8]) # esemeny K-ban
rajz_esemeny(V,Ep,'E','r')
indicatrix(1.5)
fact=4
@interact(V=(-1,1,0.1),Epx=(0,1,0.1),Epy=(0,1,0.1))
def play(V=0.2,Epx=0.6,Epy=0.8):
rajz_esemeny(V,fact*array([Epx,Epy]),'E','r')
indicatrix(1.5)
show();
V=0.25
fact=3
Ep1 =fact*array([0.3,0.8]) # esemeny K-ban
Ep2 =fact*array([0.6,0.8]) # esemeny K-ban
rajz_2esemeny(V,Ep1,Ep2,'A','r','B','limegreen')
indicatrix(1.2);
V=0.2
fact=3
Ep1 =fact*array([0.3,0.6]) # esemeny K-ban
Ep2 =fact*array([0.3,0.9]) # esemeny K-ban
rajz_2esemeny(V,Ep1,Ep2,'A','r','B','limegreen')
indicatrix(1.2)
#grid();
fact=4
@interact(V=(-1,1,0.05),Ep1x=(0,1,0.1),Ep1y=(0,1,0.1),Ep2x=(0,1,0.1),Ep2y=(0,1,0.1))
def play(V=0.25,Ep1x=0.3,Ep1y=0.8,Ep2x=0.6,Ep2y=0.8):
rajz_2esemeny(V,fact*array([Ep1x,Ep1y]),fact*array([Ep2x,Ep2y]),'A','r','B','limegreen')
indicatrix(1.5)
show();